/*************************************************************************

This class is Batch Apex class to undate the Lead Records on the following criteria

If Lead Status = 'Appointment'  AND Status Detail != 'No Show And Appointment Date < Tooday's Date

Created By : Karteek Sunkara         Date : 04-March-2012

*************************************************************************/

global class BatchClassOnLead_NoShow implements Database.Batchable<sObject> {

   global String query;

   global BatchClassOnLead_NoShow(){
      query = 'SELECT Appointment_Date__c,Id,Status,IsConverted,IsConverted__c,Status_Detail__c FROM Lead WHERE Status = \'Appointment\' AND (Status_Detail__c != \'No Show\' OR Status_Detail__c != \'No se presentó\') AND IsConverted = false  AND IsConverted__c = false AND Appointment_Date__c < Today';
   }

   global Database.QueryLocator start(Database.BatchableContext BC){   
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     
     List<Lead> lst_lead = new List<Lead>();
     for(sobject s : scope){
        lead lead_Obj = (Lead) s;
        lst_lead.add(new Lead(Id = lead_Obj.Id, Status_Detail__c = 'No Show'));
     }     
     update lst_lead;     
   }

   global void finish(Database.BatchableContext BC){
   }
   
}